//
//  Stores.m
//  A One POS
//
//  Created by AonePOS on 24/09/13.
//  Copyright (c) 2013 AonePOS. All rights reserved.
//

#import "Stores.h"
#import "DataBaseManager.h"
#import "ServersyncClass.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface Stores ()

@end

@implementation Stores
{
    UIView *sidemenu,*mainview,*backgroundcolorview;
    UIButton *categorybutton;
    UIToolbar *downtoolBar,*maintoolBar;
    UIImageView *logobackview,*logoimageview;
    int y,p;
    _Bool isLandScope;
    UIButton *helpiconButton,*logouticonButton,*menubutton;
    BOOL menuslected;
    UIButton *AddstoresBtn,*EditstoreBtn;
    UINavigationBar *navBar;
    
    //add stores view
    UIView *AddstoresBackview;
    UIScrollView *addstoresView;
    UILabel *fieldslbl,*defaluttaxLbl,*subtotallbl,*currencylbl;
    UITextField *dataField;
    UIButton *DefaulttaxBtn,*subtotalBtn,*currencyBtn,*savestoreDataBtn,*resetStoreDatabtn;
    NSString *storename,*storeid,*email,*number,*street,*city,*postalcode,*country,*state,*subtotalStr;
    UITableView *taxesTable,*currencytable;
    NSMutableArray *taxesArray,*currencyArray;
    UITextField *citytextField,*stateTextField,*CountrytextField,*postalTextField;
    
    //edit stores view
    UIView *editStoresView;
    UITableView *editstoresTable;
    NSMutableArray *storenamesArray,*storecitysArray,*storeCountrysArray,*storeStatesArray,*storestateStr,*storeIDSArray;
    UIButton *editBtn,*deleteBtn,*viewbtn;
    NSInteger selectedstore;
    UIAlertView *deleteStoreAlert;
    UIView *viewStoredataBackView;
    UITableView *ViewStoredataTable;
    NSArray *AllkeysArray,*AllvaluesArray;
    UIView *EditStoredataBackView;
    UIScrollView *EditsoreView;
    UILabel *EditFieldLbl,*EditdefaluttaxLbl,*Editsubtotallbl,*Editcurrencylbl;
    UITextField *EditdataField;
    UIButton *EditDefaulttaxBtn,*EditsubtotalBtn,*EditcurrencyBtn,*EditsavestoreDataBtn,*EditresetStoreDatabtn;
    UITableView *edittaxesTable,*editcurrencytable;
    NSString *EditSubtotalStr;
    NSString *changeStorename,*Changestoreid,*changeEmail,*Changenumber,*changestreet,*changeCity,*changePostal,*changeCountrty,*Changestate,*Changetax,*ChangeDiscount,*Changecurrency;
    
    UITableView *statesTable,*countrysTable,*citysTable;
    NSMutableArray *pastStatesArray,*pastCitysArray,*pastCountrysArray,*statesArray,*countrysArray,*citysArray;
    
    NSURLConnection *StoreConnection;
    NSMutableData *StoreResponseData;
    
    UILabel *sationLbl,*Timelbl,*EmpIdlbl;
    UIButton *logoBtn;
    
    IBOutlet StoresCell *storesCell;
    IBOutlet ViewStoresCell *viewStoresCell;
    ServersyncClass *serverSyncClassObject;
     general_data *generalDataObject;
  
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    generalDataObject =[general_data new];
    [generalDataObject  GetuserDataVariablesMethod];
    serverSyncClassObject=[ServersyncClass new];
    [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:serverSyncClassObject withObject:nil];
       [super viewDidLoad];
    
   // [NSThread detachNewThreadSelector:@selector(ServerSyncronizationMethod) toTarget:[ServersyncClass sharedInstance] withObject:nil];
    
    y=0;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
        y=y+20;
        
        
    }
    CGFloat width,height;
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    // //NSLog(@" %f,%f",width,height);
    
    backgroundcolorview=[[UIView alloc]init];
    backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
    [backgroundcolorview  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]]]];
    
    [self.view addSubview:backgroundcolorview];
    
    // [ContactsBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"contactsactive" ofType:@"png"]] forState:UIControlStateNormal];
    
    sidemenu=[[UIView alloc]init];
    sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
    //sidemenu.hidden=YES;
    //[sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluecolorstrip.jpg"]]];
    [sidemenu  setBackgroundColor:[UIColor colorWithPatternImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bluecolorstrip" ofType:@"jpg"]]]];
    
    
    NSString *pagetitle;
    pagetitle=@"Stores";
    
    navBar = [[UINavigationBar alloc] init];
    navBar.frame=CGRectMake(0, 0,width , 50.0);
    
    [navBar setBackgroundImage:[UIImage imageNamed:@"logo-login-bg-short.png"] forBarMetrics:UIBarMetricsDefault];
    
    //[navBar setBackgroundColor:[UIColor blackColor]];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    titleLabel.font=[UIFont boldSystemFontOfSize:30.0];
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.text =pagetitle;
    [self.navigationItem setTitleView:titleLabel];
    
    
    //navItem.title = pagetitle;
    [navBar pushNavigationItem:self.navigationItem animated:false];
    
    [backgroundcolorview addSubview:navBar];
    
    
    menubutton = [UIButton buttonWithType:UIButtonTypeCustom];
    [menubutton setFrame:CGRectMake(0,0,50,50)];
    [menubutton addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    [menubutton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"arrow" ofType:@"png"]] forState:UIControlStateNormal];
    [navBar addSubview:menubutton];
    
    
    logoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [logoBtn setFrame:CGRectMake(60,0,250,50)];
    // [logoBtn addTarget:self action:@selector(menuclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logoBtn setImage:[UIImage imageNamed:@"headeraonelogo.png"] forState:UIControlStateNormal];
    [logoBtn setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"headeraonelogo" ofType:@"png"]] forState:UIControlStateNormal];
    
    [navBar addSubview:logoBtn];
    sationLbl=[[UILabel alloc] init];
    
    sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
    
    [sationLbl setFont:[UIFont systemFontOfSize:13.0f]];
    [sationLbl setBackgroundColor:[UIColor clearColor]];
    [sationLbl setTextColor:[UIColor blackColor]];
    [sationLbl setText:@"Station No:1"];
    sationLbl.lineBreakMode = NSLineBreakByWordWrapping;
    sationLbl.numberOfLines = 2;
    [sationLbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:sationLbl];
    
    
    EmpIdlbl=[[UILabel alloc] init];
    EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
    
    [EmpIdlbl setFont:[UIFont systemFontOfSize:13.0f]];
    [EmpIdlbl setBackgroundColor:[UIColor clearColor]];
    [EmpIdlbl setTextColor:[UIColor blackColor]];
    [EmpIdlbl setText:[NSString stringWithFormat:@"Employee Id: %@",[generalDataObject  userID]]];
    EmpIdlbl.lineBreakMode = NSLineBreakByWordWrapping;
    // EmpIdlbl.numberOfLines = 2;
    [EmpIdlbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:EmpIdlbl];
    
    
    Timelbl=[[UILabel alloc] init];
    
    Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
    
    [Timelbl setFont:[UIFont systemFontOfSize:13.0f]];
    [Timelbl setBackgroundColor:[UIColor clearColor]];
    [Timelbl setTextColor:[UIColor blackColor]];
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
      NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    //Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    
    // timer is set & will be triggered each second
    //[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(showTime) userInfo:nil repeats:YES];
    Timelbl.lineBreakMode = NSLineBreakByWordWrapping;
    Timelbl.numberOfLines = 2;
    [Timelbl setTextAlignment:NSTextAlignmentLeft];
    [navBar addSubview:Timelbl];
    
    p=1;
    @autoreleasepool {

    for (int i=0; i< 10; i++)
    {
        
        categorybutton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [categorybutton setFrame:CGRectMake(0,p,170,40)];
        [categorybutton addTarget:self action:@selector(categotybuttonclicked:) forControlEvents:UIControlEventTouchUpInside];
        categorybutton.tag=i;
        if (categorybutton.tag == 0)
        {
            [categorybutton setImage:[UIImage imageNamed:@"posnormal2.png"] forState:UIControlStateNormal];
        }
        
        else if (categorybutton.tag == 1)
        {
            [categorybutton setImage:[UIImage imageNamed:@"profilenormal2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 2)
        {
            [categorybutton setImage:[UIImage imageNamed:@"inventorynormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 3)
        {
            [categorybutton setImage:[UIImage imageNamed:@"customernormal2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 4)
        {
            [categorybutton setImage:[UIImage imageNamed:@"employeenormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 5)
        {
            [categorybutton setImage:[UIImage imageNamed:@"settingsnormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 6)
        {
            [categorybutton setImage:[UIImage imageNamed:@"reportsnormal2.png"] forState:UIControlStateNormal];
        }
        else if(categorybutton.tag == 7)
        {
            [categorybutton setImage:[UIImage imageNamed:@"contactsnormal2.png"] forState:UIControlStateNormal];
        }
        else if (categorybutton.tag == 8)
        {
            [categorybutton setImage:[UIImage imageNamed:@"storesactive.png"] forState:UIControlStateNormal];
        }
        
        else if (categorybutton.tag == 9)
        {
            //[categorybutton setImage:[UIImage imageNamed:@"bluecolorstrip.jpg"] forState:UIControlStateNormal];
        }
        [sidemenu addSubview:categorybutton];
        p=p+categorybutton.frame.size.height;
    }
    }
    mainview=[[UIView alloc]init];
    mainview.frame=CGRectMake(20,60,width-40,height-200);
    [mainview setBackgroundColor:[UIColor grayColor]];
    [mainview  setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"hqbackground69opacity.png"]]];
    [backgroundcolorview addSubview:mainview];
    maintoolBar = [[UIToolbar alloc] init];
    maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
    [maintoolBar setBackgroundImage:[UIImage imageNamed:@"toprightmenu.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
    
    NSMutableArray *items=[[NSMutableArray alloc]init];
    [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
    AddstoresBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    AddstoresBtn.frame = CGRectMake(0, 0, 150, 60);
    
    [AddstoresBtn addTarget:self action:@selector(AddstroresClicked) forControlEvents:UIControlEventTouchUpInside];
    // [backButton setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
    AddstoresBtn.tag=[items indexOfObject:AddstoresBtn];
    [AddstoresBtn setTitle:@"Add Stores" forState:UIControlStateNormal];
    AddstoresBtn.showsTouchWhenHighlighted = YES;
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [AddstoresBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [AddstoresBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:AddstoresBtn];
    
    
    [items  addObject:backBarButtonItem];
    [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
    EditstoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    EditstoreBtn.frame = CGRectMake(0, 0, 150, 60);
    [EditstoreBtn setTitle:@"Edit Stores" forState:UIControlStateNormal];
    [EditstoreBtn addTarget:self action:@selector(EditstorsClicked) forControlEvents:UIControlEventTouchUpInside];
    EditstoreBtn.tag=[items indexOfObject:EditstoreBtn];
    //[backButton2 setBackgroundImage:[UIImage imageNamed:@"topright-highlightitem-textbg.png"] forState:UIControlStateNormal];
    EditstoreBtn.showsTouchWhenHighlighted = YES;
    
    
    UIBarButtonItem *backBarButtonItem2 = [[UIBarButtonItem alloc] initWithCustomView:EditstoreBtn];
    
    [items  addObject:backBarButtonItem2];
    [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]];
    
    
    [maintoolBar setItems:items animated:NO];
    [mainview addSubview:maintoolBar];
    
    logoimageview=[[UIImageView alloc]init];
    logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
    [logoimageview setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aoneposlogo" ofType:@"png"]]];
    [self.view addSubview:logoimageview];
    
    helpiconButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [helpiconButton setFrame:CGRectMake(width-180,y+40,70,70)];
    [helpiconButton addTarget:self action:@selector(helpiconclicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[helpiconButton setImage:[UIImage imageNamed:@"helpicon.png"] forState:UIControlStateNormal];
    [helpiconButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"helpicon" ofType:@"png"]] forState:UIControlStateNormal];
    
    [self.view addSubview:helpiconButton];
    logouticonButton = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [logouticonButton setFrame:CGRectMake(width-100,y+40,70,70)];
    [logouticonButton addTarget:self action:@selector(logoutButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    
    //[logouticonButton setImage:[UIImage imageNamed:@"logoutbutton.png"] forState:UIControlStateNormal];
    [logouticonButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"logoutbutton" ofType:@"png"]] forState:UIControlStateNormal];
    [self.view addSubview:logouticonButton];
    
    
    
    //add stores view
    [EditStoredataBackView removeFromSuperview];
    
    AddstoresBackview=[[UIView alloc]init];
    AddstoresBackview.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
    [AddstoresBackview setBackgroundColor:[UIColor whiteColor]];
    [mainview addSubview:AddstoresBackview];
    
    addstoresView =[[UIScrollView alloc]init];
    addstoresView.frame=CGRectMake(10, 10, AddstoresBackview.frame.size.width-20, AddstoresBackview.frame.size.height-20);
    addstoresView.contentSize=CGSizeMake(AddstoresBackview.frame.size.width-20,AddstoresBackview.frame.size.height+350);
    [addstoresView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    
    addstoresView.layer.cornerRadius=8;
    [AddstoresBackview addSubview:addstoresView];
    
    NSArray *labelArray;
    CGFloat labelwidth=(addstoresView.frame.size.width/4);
    int k=20;
    for (int i=0; i< 9; i++)
    {
        fieldslbl=[[UILabel alloc] init];
        fieldslbl.frame=CGRectMake(labelwidth-30, k, labelwidth+60, 40);
        
        fieldslbl.tag=i+100;
        [fieldslbl setFont:[UIFont systemFontOfSize:25.0f]];
        [fieldslbl setBackgroundColor:[UIColor clearColor]];
        [fieldslbl setTextColor:[UIColor whiteColor]];
        if (!labelArray)
       labelArray=[[NSArray alloc] initWithObjects:@"Store Name* ",@"Store Id* ",@"Store Email",@"Contact Number ",@"Street ",@"City",@"Zip/Postal Code",@"Country",@"State",@" ",nil];
        [fieldslbl setText:[labelArray objectAtIndex:i]];
        [fieldslbl setTextAlignment:NSTextAlignmentLeft];
        [addstoresView addSubview:fieldslbl];
        
        k=k+60;
    }
    int j=20;
    for (int i=0; i< 5; i++)
    {
        dataField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        dataField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, j,labelwidth, 40);
        dataField.delegate=self;
        dataField.tag=i+100;
        
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        // // //NSLog(@"%f",dataField.frame.origin.y);
        dataField.leftView = paddingview;
        dataField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        dataField.leftViewMode = UITextFieldViewModeAlways;
        [dataField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [dataField setAutocorrectionType:UITextAutocorrectionTypeNo];
        
        [dataField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
        if (dataField.tag == 105)
        {
            [dataField setBackground:[UIImage imageNamed:@" "]];
            
        }
        [dataField setReturnKeyType:UIReturnKeyNext];
        
        [addstoresView addSubview:dataField];
        
        
        j=j+60;
        paddingview=nil;
    }
    
    //// //NSLog(@"%d",k);
    citytextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    citytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 320,labelwidth, 40);
    citytextField.delegate=self;
    
    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    citytextField.leftView = paddingview;
    citytextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    citytextField.leftViewMode = UITextFieldViewModeAlways;
    [citytextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [citytextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:citytextField];
    postalTextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    postalTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 380,labelwidth, 40);
    postalTextField.delegate=self;
    
    UIView *paddingview1=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    postalTextField.leftView = paddingview1;
    postalTextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    postalTextField.leftViewMode = UITextFieldViewModeAlways;
    [postalTextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [postalTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:postalTextField];
    CountrytextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    CountrytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 440,labelwidth, 40);
    CountrytextField.delegate=self;
    
    UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    CountrytextField.leftView = paddingview2;
    CountrytextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    CountrytextField.leftViewMode = UITextFieldViewModeAlways;
    [CountrytextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [CountrytextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:CountrytextField];
    stateTextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    stateTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 500,labelwidth, 40);
    stateTextField.delegate=self;
    
    UIView *paddingview3=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    stateTextField.leftView = paddingview3;
    stateTextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    stateTextField.leftViewMode = UITextFieldViewModeAlways;
    [stateTextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [stateTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    [addstoresView addSubview:stateTextField];
    
    citysTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 360,labelwidth,100) style:UITableViewStylePlain];
    citysTable.backgroundColor=[UIColor whiteColor];
    citysTable.delegate = self;
    citysTable.dataSource = self;
    citysTable.scrollEnabled = YES;
    citysTable.hidden=YES;
    [citysTable.layer setBorderWidth: 1.0];
    [citysTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:citysTable];
    countrysTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 480,labelwidth,100) style:UITableViewStylePlain];
    countrysTable.backgroundColor=[UIColor whiteColor];
    countrysTable.delegate = self;
    countrysTable.dataSource = self;
    countrysTable.scrollEnabled = YES;
    countrysTable.hidden=YES;
    [countrysTable.layer setBorderWidth: 1.0];
    [countrysTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:countrysTable];
    statesTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 400,labelwidth,100) style:UITableViewStylePlain];
    statesTable.backgroundColor=[UIColor whiteColor];
    statesTable.delegate = self;
    statesTable.dataSource = self;
    statesTable.scrollEnabled = YES;
    statesTable.hidden=YES;
    [statesTable.layer setBorderWidth: 1.0];
    [statesTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:statesTable];
    
    defaluttaxLbl=[[UILabel alloc] init];
    defaluttaxLbl.frame=CGRectMake(labelwidth-5,560,labelwidth+60, 40);
    
    
    [defaluttaxLbl setFont:[UIFont systemFontOfSize:25.0f]];
    [defaluttaxLbl setBackgroundColor:[UIColor clearColor]];
    [defaluttaxLbl setTextColor:[UIColor whiteColor]];
    [defaluttaxLbl setText:@"Default Tax"];
    [defaluttaxLbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:defaluttaxLbl];
    
    DefaulttaxBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    DefaulttaxBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,560, labelwidth, 40);
    
    [DefaulttaxBtn setTag:1];
    [DefaulttaxBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    DefaulttaxBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [DefaulttaxBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [DefaulttaxBtn addTarget:self action:@selector(DefaulttaxClick) forControlEvents:UIControlEventTouchUpInside];
    [addstoresView addSubview:DefaulttaxBtn];
    
    
    subtotallbl=[[UILabel alloc] init];
    subtotallbl.frame=CGRectMake(labelwidth-5, 620, labelwidth+50, 40);
    [subtotallbl setFont:[UIFont systemFontOfSize:25.0f]];
    [subtotallbl setBackgroundColor:[UIColor clearColor]];
    [subtotallbl setTextColor:[UIColor whiteColor]];
    [subtotallbl setText:@"Subtotal Discount"];
    [subtotallbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:subtotallbl];
    
    subtotalStr=@"false";
    
    subtotalBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    subtotalBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width+10,620, 40, 40);
    
    [subtotalBtn setTag:1];
    [subtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-off.png"] forState:UIControlStateNormal];
    [subtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-on.png"] forState:UIControlStateSelected];
    
    subtotalBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [subtotalBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [subtotalBtn addTarget:self action:@selector(subtotalclicked) forControlEvents:UIControlEventTouchUpInside];
    
    [addstoresView addSubview:subtotalBtn];
    
    currencylbl=[[UILabel alloc] init];
    currencylbl.frame=CGRectMake(labelwidth-5, 680, labelwidth+60, 40);
    
    
    [currencylbl setFont:[UIFont systemFontOfSize:25.0f]];
    [currencylbl setBackgroundColor:[UIColor clearColor]];
    [currencylbl setTextColor:[UIColor whiteColor]];
    [currencylbl setText:@"Currency"];
    [currencylbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:currencylbl];
    
    currencyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    currencyBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,680, labelwidth, 40);
    
    [currencyBtn setTag:1];
    [currencyBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    currencyBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [currencyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [currencyBtn addTarget:self action:@selector(currencybtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [addstoresView addSubview:currencyBtn];
    savestoreDataBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    savestoreDataBtn.frame=CGRectMake(labelwidth+60,760,100, 30);
    [savestoreDataBtn addTarget:self action:@selector(saveStoredataCliked) forControlEvents:UIControlEventTouchUpInside];
    
    //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
    [savestoreDataBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [savestoreDataBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
    [addstoresView addSubview:savestoreDataBtn];
    
    resetStoreDatabtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    resetStoreDatabtn.frame=CGRectMake(labelwidth+220, 760, 100, 30);
    [resetStoreDatabtn addTarget:self action:@selector(ResetstoredataClicked) forControlEvents:UIControlEventTouchUpInside];
    [resetStoreDatabtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [resetStoreDatabtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
    
    [addstoresView addSubview:resetStoreDatabtn];
    taxesTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100) style:UITableViewStylePlain];
    taxesTable.backgroundColor=[UIColor whiteColor];
    taxesTable.delegate = self;
    taxesTable.dataSource = self;
    taxesTable.scrollEnabled = YES;
    taxesTable.hidden=YES;
    [taxesTable.layer setBorderWidth: 1.0];
    [taxesTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:taxesTable];
    
    currencytable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100) style:UITableViewStylePlain];
    currencytable.backgroundColor=[UIColor whiteColor];
    currencytable.delegate = self;
    currencytable.dataSource = self;
    currencytable.scrollEnabled = YES;
    currencytable.hidden=YES;
    [currencytable.layer setBorderWidth: 1.0];
    [currencytable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:currencytable];
    taxesArray=[[NSMutableArray alloc]initWithObjects:@"12",@"13",@"24", nil];
    currencyArray=[[NSMutableArray alloc]initWithObjects:@"$",nil];
    
    /*storename=[[NSString alloc]init];
    storeid=[[NSString alloc]init];
    email=[[NSString alloc]init];
    number=[[NSString alloc]init];
    street=[[NSString alloc]init];
    city=[[NSString alloc]init];
    postalcode=[[NSString alloc]init];
    country=[[NSString alloc]init];
    state=[[NSString alloc]init];
    //subtotalStr=[[NSString alloc]init];
    EditSubtotalStr=[[NSString alloc]init];
    
    changeStorename=[[NSString alloc]init];
    Changestoreid=[[NSString alloc]init];
    changeEmail=[[NSString alloc]init];
    Changenumber=[[NSString alloc]init];
    changestreet=[[NSString alloc]init];
    changeCity=[[NSString alloc]init];
    changePostal=[[NSString alloc]init];
    changeCountrty=[[NSString alloc]init];
    Changestate=[[NSString alloc]init];
    Changetax=[[NSString alloc]init];
    ChangeDiscount=[[NSString alloc]init];
    Changecurrency=[[NSString alloc]init];*/
    
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
   
    helpiconButton.hidden=YES;

    // Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
    isLandScope = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    [self updateUI];
    NSString *selectQuery=[NSString stringWithFormat:@"select city,country,state from store_details"];
    NSMutableArray *storesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storesArray];
   
        statesArray=[[NSMutableArray alloc]init];
        countrysArray=[[NSMutableArray alloc]init];
        citysArray=[[NSMutableArray alloc]init];
        pastCitysArray=[[NSMutableArray alloc]init];
        pastCountrysArray=[[NSMutableArray alloc]init];
        pastStatesArray=[[NSMutableArray alloc]init];
    
    @autoreleasepool {
        for (NSDictionary *myDict in storesArray)
        {
            NSString *storecityStr=[myDict objectForKey:@"city"];
            NSString *storestatestr=[myDict objectForKey:@"state"];
            NSString *storecountrystr=[myDict objectForKey:@"country"];
            [pastStatesArray addObject:storestatestr];
            [pastCitysArray addObject:storecityStr];
            [pastCountrysArray addObject:storecountrystr];
            
        }
    }
  
    [super viewWillAppear:YES];
}
-(void)showTime
{
    
    NSDate *aDate = [NSDate date];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterShortStyle];
    [formatter setTimeStyle:NSDateFormatterNoStyle];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSString *datestr;
    datestr=[formatter stringFromDate:aDate];
    Timelbl.text=datestr;
    // Timelbl.text=[NSString stringWithFormat:@"%@:%@",@"Time",datestr];
    //Timelbl.text=[[NSDate date] description];
    
    
}
-(void)AddstroresClicked
{
    
    NSArray *EditsoreViewArray = EditsoreView.subviews;
    for (int i = 0; i<[EditsoreViewArray count]; i++) {
        UIView *vi =[EditsoreViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *EditStoredataBackViewArray = EditStoredataBackView.subviews;
    for (int i = 0; i<[EditStoredataBackViewArray count]; i++) {
        UIView *vi =[EditStoredataBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [editStoresView removeFromSuperview],[EditStoredataBackView removeFromSuperview];
    
    [EditstoreBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [EditstoreBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [AddstoresBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [AddstoresBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [editstoresTable removeFromSuperview];
    [EditStoredataBackView removeFromSuperview];
    
//Add store view
    if (!AddstoresBackview)
    AddstoresBackview=[[UIView alloc]init];
    AddstoresBackview.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
    [AddstoresBackview setBackgroundColor:[UIColor whiteColor]];
    [mainview addSubview:AddstoresBackview];
     if (!addstoresView)
    addstoresView =[[UIScrollView alloc]init];
    addstoresView.frame=CGRectMake(10, 10, AddstoresBackview.frame.size.width-20, AddstoresBackview.frame.size.height-20);
    addstoresView.contentSize=CGSizeMake(AddstoresBackview.frame.size.width-20,AddstoresBackview.frame.size.height+350);
    [addstoresView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    
    addstoresView.layer.cornerRadius=8;
    [AddstoresBackview addSubview:addstoresView];
      CGFloat labelwidth=(addstoresView.frame.size.width/4);
   
    NSArray *labelArray;
  
    int k=20;
    for (int i=0; i< 9; i++)
    {
        fieldslbl=[[UILabel alloc] init];
        fieldslbl.frame=CGRectMake(labelwidth-30, k, labelwidth+60, 40);
        
        fieldslbl.tag=i+100;
        [fieldslbl setFont:[UIFont systemFontOfSize:25.0f]];
        [fieldslbl setBackgroundColor:[UIColor clearColor]];
        [fieldslbl setTextColor:[UIColor whiteColor]];
        if (!labelArray)
        labelArray=[[NSArray alloc] initWithObjects:@"Store Name* ",@"Store Id* ",@"Store Email",@"Contact Number ",@"Street ",@"City",@"Zip/Postal Code",@"Country",@"State",@" ",nil];
        [fieldslbl setText:[labelArray objectAtIndex:i]];
        [fieldslbl setTextAlignment:NSTextAlignmentLeft];
        [addstoresView addSubview:fieldslbl];
        
        k=k+60;
    }
    int j=20;
    for (int i=0; i< 5; i++)
    {
        dataField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        dataField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, j,labelwidth, 40);
        dataField.delegate=self;
        dataField.tag=i+100;
        
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        // // //NSLog(@"%f",dataField.frame.origin.y);
        dataField.leftView = paddingview;
        dataField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        dataField.leftViewMode = UITextFieldViewModeAlways;
        [dataField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [dataField setAutocorrectionType:UITextAutocorrectionTypeNo];
        
        [dataField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
        if (dataField.tag == 105)
        {
            [dataField setBackground:[UIImage imageNamed:@" "]];
            
        }
        [dataField setReturnKeyType:UIReturnKeyNext];
        
        [addstoresView addSubview:dataField];
        
        
        j=j+60;
    }
   
    //// //NSLog(@"%d",k);
    if (!citytextField)
    citytextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    citytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 320,labelwidth, 40);
    citytextField.delegate=self;
    
    UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    citytextField.leftView = paddingview;
    citytextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    citytextField.leftViewMode = UITextFieldViewModeAlways;
    [citytextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [citytextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:citytextField];
     if (!postalTextField)
    postalTextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    postalTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 380,labelwidth, 40);
    postalTextField.delegate=self;
    
    UIView *paddingview1=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    postalTextField.leftView = paddingview1;
    postalTextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    postalTextField.leftViewMode = UITextFieldViewModeAlways;
    [postalTextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [postalTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:postalTextField];
    if (!CountrytextField)
    CountrytextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    CountrytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 440,labelwidth, 40);
    CountrytextField.delegate=self;
    
    UIView *paddingview2=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    CountrytextField.leftView = paddingview2;
    CountrytextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    CountrytextField.leftViewMode = UITextFieldViewModeAlways;
    [CountrytextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [CountrytextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    //[citytextField addTarget:self action:@selector(datatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
    
    [addstoresView addSubview:CountrytextField];
     if (!stateTextField)
    stateTextField=[[UITextField alloc] init];
    //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
    stateTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 500,labelwidth, 40);
    stateTextField.delegate=self;
    
    UIView *paddingview3=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
    // // //NSLog(@"%f",dataField.frame.origin.y);
    stateTextField.leftView = paddingview3;
    stateTextField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
    stateTextField.leftViewMode = UITextFieldViewModeAlways;
    [stateTextField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
    [stateTextField setAutocorrectionType:UITextAutocorrectionTypeNo];
    
    [addstoresView addSubview:stateTextField];
    if (!citysTable)
    citysTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 360,labelwidth,100) style:UITableViewStylePlain];
    citysTable.backgroundColor=[UIColor whiteColor];
    citysTable.delegate = self;
    citysTable.dataSource = self;
    citysTable.scrollEnabled = YES;
    citysTable.hidden=YES;
    [citysTable.layer setBorderWidth: 1.0];
    [citysTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:citysTable];
    if (!countrysTable)
    countrysTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 480,labelwidth,100) style:UITableViewStylePlain];
    countrysTable.backgroundColor=[UIColor whiteColor];
    countrysTable.delegate = self;
    countrysTable.dataSource = self;
    countrysTable.scrollEnabled = YES;
    countrysTable.hidden=YES;
    [countrysTable.layer setBorderWidth: 1.0];
    [countrysTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:countrysTable];
     if (!statesTable)
    statesTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 400,labelwidth,100) style:UITableViewStylePlain];
    statesTable.backgroundColor=[UIColor whiteColor];
    statesTable.delegate = self;
    statesTable.dataSource = self;
    statesTable.scrollEnabled = YES;
    statesTable.hidden=YES;
    [statesTable.layer setBorderWidth: 1.0];
    [statesTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:statesTable];
     if (!defaluttaxLbl)
    defaluttaxLbl=[[UILabel alloc] init];
    defaluttaxLbl.frame=CGRectMake(labelwidth-5,560,labelwidth+60, 40);
    [defaluttaxLbl setFont:[UIFont systemFontOfSize:25.0f]];
    [defaluttaxLbl setBackgroundColor:[UIColor clearColor]];
    [defaluttaxLbl setTextColor:[UIColor whiteColor]];
    [defaluttaxLbl setText:@"Default Tax"];
    [defaluttaxLbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:defaluttaxLbl];
     if (!DefaulttaxBtn)
    DefaulttaxBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    DefaulttaxBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,560, labelwidth, 40);
    [DefaulttaxBtn setTag:1];
    [DefaulttaxBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    DefaulttaxBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [DefaulttaxBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [DefaulttaxBtn addTarget:self action:@selector(DefaulttaxClick) forControlEvents:UIControlEventTouchUpInside];
    [addstoresView addSubview:DefaulttaxBtn];
    
    if (!subtotallbl)
    subtotallbl=[[UILabel alloc] init];
    subtotallbl.frame=CGRectMake(labelwidth-5, 620, labelwidth+50, 40);
    [subtotallbl setFont:[UIFont systemFontOfSize:25.0f]];
    [subtotallbl setBackgroundColor:[UIColor clearColor]];
    [subtotallbl setTextColor:[UIColor whiteColor]];
    [subtotallbl setText:@"Subtotal Discount"];
    [subtotallbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:subtotallbl];
    
    subtotalStr=@"false";
     if (!subtotalBtn)
    subtotalBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    subtotalBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width+10,620, 40, 40);
    
    [subtotalBtn setTag:1];
    [subtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-off.png"] forState:UIControlStateNormal];
    [subtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-on.png"] forState:UIControlStateSelected];
    
    subtotalBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [subtotalBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [subtotalBtn addTarget:self action:@selector(subtotalclicked) forControlEvents:UIControlEventTouchUpInside];
    
    [addstoresView addSubview:subtotalBtn];
     if (!currencylbl)
    currencylbl=[[UILabel alloc] init];
    currencylbl.frame=CGRectMake(labelwidth-5, 680, labelwidth+60, 40);
    [currencylbl setFont:[UIFont systemFontOfSize:25.0f]];
    [currencylbl setBackgroundColor:[UIColor clearColor]];
    [currencylbl setTextColor:[UIColor whiteColor]];
    [currencylbl setText:@"Currency"];
    [currencylbl setTextAlignment:NSTextAlignmentLeft];
    [addstoresView addSubview:currencylbl];
    if (!currencyBtn)
    currencyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    currencyBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,680, labelwidth, 40);
    [currencyBtn setTag:1];
    [currencyBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    currencyBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [currencyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [currencyBtn addTarget:self action:@selector(currencybtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [addstoresView addSubview:currencyBtn];
     if (!savestoreDataBtn)
    savestoreDataBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    savestoreDataBtn.frame=CGRectMake(labelwidth+60,760,100, 30);
    [savestoreDataBtn addTarget:self action:@selector(saveStoredataCliked) forControlEvents:UIControlEventTouchUpInside];
    
    //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
    [savestoreDataBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [savestoreDataBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
    [addstoresView addSubview:savestoreDataBtn];
      if (!resetStoreDatabtn)
    resetStoreDatabtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    resetStoreDatabtn.frame=CGRectMake(labelwidth+220, 760, 100, 30);
    [resetStoreDatabtn addTarget:self action:@selector(ResetstoredataClicked) forControlEvents:UIControlEventTouchUpInside];
    [resetStoreDatabtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [resetStoreDatabtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
    
    [addstoresView addSubview:resetStoreDatabtn];
     if (!taxesTable)
    taxesTable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100) style:UITableViewStylePlain];
    taxesTable.backgroundColor=[UIColor whiteColor];
    taxesTable.delegate = self;
    taxesTable.dataSource = self;
    taxesTable.scrollEnabled = YES;
    taxesTable.hidden=YES;
    [taxesTable.layer setBorderWidth: 1.0];
    [taxesTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:taxesTable];
       if (!currencytable)
    currencytable = [[UITableView alloc] initWithFrame:CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100) style:UITableViewStylePlain];
    currencytable.backgroundColor=[UIColor whiteColor];
    currencytable.delegate = self;
    currencytable.dataSource = self;
    currencytable.scrollEnabled = YES;
    currencytable.hidden=YES;
    [currencytable.layer setBorderWidth: 1.0];
    [currencytable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [addstoresView addSubview:currencytable];
    if (!taxesArray)
    {
    taxesArray=[[NSMutableArray alloc]initWithObjects:@"12",@"13",@"24", nil];
    currencyArray=[[NSMutableArray alloc]initWithObjects:@"$",nil];
    }

    
   // [mainview addSubview:AddstoresBackview];
    
    storeCountrysArray=nil;
    storecitysArray=nil;
    storenamesArray=nil;
    storeStatesArray=nil;
    storeIDSArray=nil;
    
}
-(void)EditstorsClicked
{
    NSArray *addstoresViewArray = addstoresView.subviews;
    for (int i = 0; i<[addstoresViewArray count]; i++) {
        UIView *vi =[addstoresViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *AddstoresBackviewArray = AddstoresBackview.subviews;
    for (int i = 0; i<[AddstoresBackviewArray count]; i++) {
        UIView *vi =[AddstoresBackviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [addstoresView removeFromSuperview],[AddstoresBackview removeFromSuperview];
   

    [AddstoresBtn setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [AddstoresBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIImage *btnImg = [UIImage imageNamed:@"highlightedtopmenuitem.png"];
    UIImage *btnGreyImg = [btnImg stretchableImageWithLeftCapWidth:0 topCapHeight:1];
    [EditstoreBtn setBackgroundImage:btnGreyImg forState:UIControlStateNormal];
    [EditstoreBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [AddstoresBackview removeFromSuperview];
    
     if (!editStoresView)
    editStoresView=[[UIView alloc]init];
    editStoresView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
    [editStoresView setBackgroundColor:[UIColor whiteColor]];
    [mainview addSubview:editStoresView];
   [self getStoreDataMethod];
    if (!editstoresTable)
    editstoresTable =[[UITableView alloc]init];
    editstoresTable.frame=CGRectMake(10, 10, editStoresView.frame.size.width-20, editStoresView.frame.size.height-20);
    editstoresTable.delegate=self;
    editstoresTable.dataSource=self;
    [editstoresTable setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    
    editstoresTable.layer.cornerRadius=8;
    [editStoresView addSubview:editstoresTable];

}
-(void) getStoreDataMethod
{
     NSString *selectQuery=[NSString stringWithFormat:@"select store_name,store_id,email, phonenumber,street,city,postal,country,state,defaulttax,discount,currency, created_timestamp,modified_timestamp,server_local,unique_id from store_details"];
    NSMutableArray *storesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storesArray];
    
    storeCountrysArray=[[NSMutableArray alloc]init];
    storecitysArray=[[NSMutableArray alloc]init];
    storenamesArray=[[NSMutableArray alloc]init];
    storeStatesArray=[[NSMutableArray alloc]init];
    storeIDSArray=[[NSMutableArray alloc]init];
    
    @autoreleasepool {
        for (NSDictionary *myDict in storesArray)
        {
            NSString *storenamestr=[myDict objectForKey:@"store_name"];
            NSString *storecityStr=[myDict objectForKey:@"city"];
            NSString *storestatestr=[myDict objectForKey:@"state"];
            NSString *storecountrystr=[myDict objectForKey:@"country"];
            NSString *storeIDStr=[myDict objectForKey:@"store_id"];
            [storenamesArray addObject:storenamestr];
            [storeStatesArray addObject:storestatestr];
            [storecitysArray addObject:storecityStr];
            [storeCountrysArray addObject:storecountrystr];
            [storeIDSArray addObject:storeIDStr];
        }
    }
    [editstoresTable reloadData];
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
    
    // Put anything that starts with this substring into the autocompleteUrls array
    // The items in this array is what will show up in the table view
    if ([substring length]>=1)
    {
        
        
        [citysArray removeAllObjects];
        for(NSMutableString *curString in pastCitysArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:substring options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [citysArray addObject:curString];
            
        }
     
        [citysTable reloadData];
    }
    else
    {
        citysTable.hidden=YES;
    }
}
- (void)searchAutocompleteEntriesWithstring:(NSString *)string
{
    
    if ([string length]>=2)
    {
        
        
        [countrysArray removeAllObjects];
        for(NSMutableString *curString in pastCountrysArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:string options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [countrysArray addObject:curString];
            
        }
       
        
        [countrysTable reloadData];
    }
    else
    {
        countrysTable.hidden=YES;
    }
    
    
}
- (void)searchAutocompleteEntriesWithstr:(NSString *)str
{
    
    if ([str length]>=2)
    {
        
        
        [statesArray removeAllObjects];
        for(NSMutableString *curString in pastStatesArray)
        {
            NSRange titleResultsRange = [curString rangeOfString:str options:NSCaseInsensitiveSearch];
            
            if (titleResultsRange.length > 0)
                [statesArray addObject:curString];
            
        }
        
       
        [statesTable reloadData];
    }
    else
    {
        statesTable.hidden=YES;
    }
    
    
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    
    if(textField == self->citytextField)
    {
           citysTable.hidden = NO;
        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring:substring];
    }
   else if(textField== self->CountrytextField)
    {
        
         countrysTable.hidden = NO;
        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithstring:substring];
        
    }
   else if(textField== self->stateTextField)
   {
        statesTable.hidden = NO;
      // DefaulttaxBtn.hidden=YES;
       
       NSString *substring = [NSString stringWithString:textField.text];
       substring = [substring stringByReplacingCharactersInRange:range withString:string];
       [self searchAutocompleteEntriesWithstr:substring];
       
   }
    return YES;
}


-(void)datatextfieldClicked:(UITextField *)sender
{
    
    NSInteger selected=sender.tag;
    
    if (selected == 100)
    {
        
        storename=sender.text;
    }
    if (selected == 101)
    {
        storeid=sender.text;
    }
    if (selected == 102)
    {
        email=sender.text;
    }
    if (selected == 103)
    {
        
        number=sender.text;
    }
    if (selected == 104)
    {
        
        street=sender.text;
    }
    
}
-(void)subtotalclicked
{
    if (subtotalBtn.selected)
    {
        [subtotalBtn setSelected:NO];
        
        subtotalStr=@"false";
    }
    else if(!subtotalBtn.selected)
    {
        [subtotalBtn setSelected:YES];
        subtotalStr=@"true";
        
    }
    // //NSLog(@"%@",subtotalStr);
}
-(void)DefaulttaxClick
{
    
    if (taxesTable.hidden==1)
    {
        
        taxesTable.hidden=NO;
        subtotalBtn.hidden=YES;
        
    }
    else if (taxesTable.hidden==0)
    {
        [taxesTable setHidden:YES];
        
        subtotalBtn.hidden=NO;
      
    }
    
   
    
}
-(void)currencybtnClicked
{
    
    if (currencytable.hidden==1)
    {
        
        currencytable.hidden=NO;
        
        
    }else if (currencytable.hidden==0)
    {
        [currencytable setHidden:YES];
        
       
        
    }
}
-(void)saveStoredataCliked
{
     NSString *selectQuery=[NSString stringWithFormat:@"select store_id from store_details"];
    NSMutableArray *storesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storesArray];
    
    storeIDSArray=[[NSMutableArray alloc]init];
    @autoreleasepool {
        for (NSDictionary *myDict in storesArray)
        {
            NSString *storeIDStr=[myDict objectForKey:@"store_id"];
            
            [storeIDSArray addObject:storeIDStr];
        }
    }
  
    city=citytextField.text;
    postalcode=postalTextField.text;
    country=CountrytextField.text;
    state=stateTextField.text;
    // //NSLog(@"store ids %@",storeIDSArray);
    NSUInteger objIdx = [storeIDSArray containsObject:storeid];
    // //NSLog(@"%lu",(unsigned long)objIdx);
    if(objIdx == 0) {
        // //NSLog(@"condition true");
        NSString *currency=[NSString stringWithFormat:@"%@", currencyBtn.titleLabel.text];
        NSString *defaluttax=[NSString stringWithFormat:@"%@", DefaulttaxBtn.titleLabel.text];
        
        NSString *insertSQL =@"insert into store_details (store_name,store_id,email,phonenumber,street,city,postal,country,state,defaulttax,discount,currency,unique_id,created_timestamp,modified_timestamp) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        NSMutableArray *insertArray=[[NSMutableArray alloc]initWithObjects:storename,storeid,email,number,street,city,postalcode,country,state,defaluttax,subtotalStr,currency,[generalDataObject  genRandStringLength:20],[generalDataObject getsystemDatetime],[generalDataObject getsystemDatetime], nil];
        
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:insertArray];
        
       NSString *selectQuery=[NSString stringWithFormat:@"select store_name,store_id,email,phonenumber,street,city,postal,country,state,defaulttax,discount,currency,unique_id,created_timestamp,modified_timestamp,server_local from store_details where store_id='%@'",storeid];
        NSMutableArray *storeDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storeDataArray];
        
        NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
        [CategoryDict setObject:storeDataArray forKey:@"fields"];
        NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
        
        
        NSError *err;
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
        
        NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        if(![generalDataObject  connectedToInternet]){
            
            NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
            NSMutableArray *pendingsArray=[[NSMutableArray alloc]initWithObjects:@"INSERT",[generalDataObject  userID],@"saveinfo.php?",str,@"store_details",[generalDataObject getsystemDatetime], nil];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:pendingsArray];
            
        }
        else if([generalDataObject  connectedToInternet]){
            
            if ([[generalDataObject  OriginalbaseURLstr] length]>0)
            {
            
            // //NSLog(@"%@",str);
            NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=store_details&systemtime=%@&userid=%@&sessionid=%@&data=%@",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  genRandStringLength:20],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
             //NSLog(@"%@",str);
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
             //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            StoreConnection = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [StoreConnection start];
            }
        }

        for (int i=0; i<5; i++)
        {
            

            [(UITextField *)[dataField viewWithTag:i+100] setText:@""];
              // [addstoresView addSubview:mytextfield]
        }
     
     
        citytextField.text=@"";
        CountrytextField.text=@"";
        stateTextField.text=@"";
        postalTextField.text=@"";
        
        // Do some alter stuff here
    }else{
       UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"message" message:@"Store ID already exist change the store id" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
       [alert show];
       
   }
    
    // //NSLog(@"%@",[dbMgr  storedataArray]);

}
- (void)clearAll
{
    for (UIViewController *vc in self.tabBarController.viewControllers) {
        for (UIView *view in vc.view.subviews) {
            if ([view isKindOfClass:[UITextField class]]) {
                UITextField *textField = (UITextField *)view;
                textField.text = nil;
            }
        }
    }
}
-(void)ResetstoredataClicked
{
    [dataField setText:@""];
}


-(BOOL)shouldAutorotate
{
    // //NSLog(@"called");
    
    
    return YES;
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    // This will create a "invisible" footer
    return 0.01f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
    
    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView== taxesTable){
        return [taxesArray count];
        
    }else if (tableView== currencytable){
        return [currencyArray count];
        
    }else if (tableView== edittaxesTable){
        return [taxesArray count];
        
    }else if (tableView== editcurrencytable){
        return [currencyArray count];
        
    }else if (tableView== editstoresTable){
        return [storenamesArray count]+1;
        
    }else if (tableView== ViewStoredataTable){
        return [AllkeysArray count];
        
    }else if (tableView== citysTable){
        return [citysArray count];
        
    }else if (tableView== countrysTable){
        return [countrysArray count];
        
    }else if (tableView== statesTable){
        return [statesArray count];
        
    }
    return YES;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == editstoresTable){
        
        StoresCell  *cell = (StoresCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"StoresCell" owner:self options:nil];
            cell = storesCell;
        }
        
        // // //NSLog(@"Dict :-%@",dict);
        if (indexPath.row==0){
            cell.name_TextView.text = @"Name";
            cell.city_TextView.text =@"City";
            cell.country_TextView.text =@"Country";
            cell.state_TextView.text =@"State";
          
            
            cell.name_TextView.textColor=[UIColor blackColor];
            cell.city_TextView.textColor=[UIColor blackColor];
            cell.country_TextView.textColor=[UIColor blackColor];
            cell.state_TextView.textColor=[UIColor blackColor];
           
            cell.contentView.backgroundColor=[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f];
            cell.edit_Button.hidden=YES;
            cell.view_Button.hidden=YES;
            cell.delete_Button.hidden=YES;
            
        }else{
            
            
            cell.name_TextView.text = [storenamesArray objectAtIndex:indexPath.row-1];
            cell.city_TextView.text =[storecitysArray objectAtIndex:indexPath.row-1];
            cell.country_TextView.text =[storeCountrysArray objectAtIndex:indexPath.row-1];
            cell.state_TextView.text =[storeStatesArray objectAtIndex:indexPath.row-1];
          
            
            cell.name_TextView.textColor=[UIColor whiteColor];
            cell.city_TextView.textColor=[UIColor whiteColor];
            cell.country_TextView.textColor=[UIColor whiteColor];
            cell.state_TextView.textColor=[UIColor whiteColor];
            
            cell.edit_Button.hidden=NO;
            cell.view_Button.hidden=NO;
           cell.delete_Button.hidden=NO;
            
            cell.edit_Button.tag=indexPath.row;
            cell.view_Button.tag=indexPath.row;
            cell.delete_Button.tag=indexPath.row;
            
            
            
            
            if (indexPath.row%2==0){
                
                cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
            }else
            {
                cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
                
            }
            
        }
        
        
        return cell;
        
    } if (tableView == ViewStoredataTable){
        
        ViewStoresCell  *cell = (ViewStoresCell *)[tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
        
        if(!cell) {
            [[NSBundle mainBundle] loadNibNamed:@"ViewStoresCell" owner:self options:nil];
            cell = viewStoresCell;
        }
        
            cell.key_TextView.text = [AllkeysArray objectAtIndex:indexPath.row];
            cell.value_TextView.text =[AllvaluesArray objectAtIndex:indexPath.row];
        
            
            cell.key_TextView.textColor=[UIColor whiteColor];
            cell.value_TextView.textColor=[UIColor whiteColor];
        
          if (indexPath.row%2==0){
                
                cell.contentView.backgroundColor=[UIColor colorWithRed:64.0f/255.0f green:96.0f/255.0f blue:120.0f/255.0f alpha:1.0f];
            }else
            {
                cell.contentView.backgroundColor=[UIColor colorWithRed:56.0f/255.0f green:104.0f/255.0f blue:128.0f/255.0f alpha:1.0f];
                
            }
            
        
        return cell;
        
    }else{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        if(!cell) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
        }
    
    if (tableView== citysTable){
        
        cell.textLabel.text=[citysArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== countrysTable){
        
        cell.textLabel.text=[countrysArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== statesTable){
        
        cell.textLabel.text=[statesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== taxesTable){
        
        cell.textLabel.text=[taxesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== currencytable){
        
        cell.textLabel.text=[currencyArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== edittaxesTable){
        
        cell.textLabel.text=[taxesArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }else if (tableView== editcurrencytable){
        
        cell.textLabel.text=[currencyArray objectAtIndex:indexPath.row];
        cell.textLabel.textAlignment=NSTextAlignmentCenter;
    }
    
 
    return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==taxesTable){
        
        taxesTable.hidden=YES;
        subtotalBtn.hidden=NO;
       
        NSString *selectedstr=[taxesArray objectAtIndex:indexPath.row];
        [DefaulttaxBtn setTitle:selectedstr forState:UIControlStateNormal];
        
    }else if (tableView==currencytable){
        
        currencytable.hidden=YES;
       
        resetStoreDatabtn.hidden=NO;
        NSString *selectedstr=[currencyArray objectAtIndex:indexPath.row];
        [currencyBtn setTitle:selectedstr forState:UIControlStateNormal];
        
    }else if (tableView==edittaxesTable){
        
        edittaxesTable.hidden=YES;
        EditsubtotalBtn.hidden=NO;
        
        NSString *selectedstr=[taxesArray objectAtIndex:indexPath.row];
        [EditDefaulttaxBtn setTitle:selectedstr forState:UIControlStateNormal];
        
    }else if (tableView==editcurrencytable){
        
        editcurrencytable.hidden=YES;
        
        EditresetStoreDatabtn.hidden=NO;
        NSString *selectedstr=[currencyArray objectAtIndex:indexPath.row];
        [EditcurrencyBtn setTitle:selectedstr forState:UIControlStateNormal];
        
    }else if (tableView == citysTable){
        citysTable.hidden=YES;
        NSString *cityvalue=[citysArray objectAtIndex:indexPath.row];
        [citytextField setText:cityvalue];
    }else if (tableView == countrysTable){
        countrysTable.hidden=YES;
        NSString *cityvalue=[countrysArray objectAtIndex:indexPath.row];
        [CountrytextField setText:cityvalue];
    }else if (tableView == statesTable){
        DefaulttaxBtn.hidden=NO;
        statesTable.hidden=YES;
        NSString *statevalue=[statesArray objectAtIndex:indexPath.row];
        [stateTextField setText:statevalue];
    }
    
}


-(void)ViewStoredataClicked:(UIButton *)sender
{
    
    
}
-(void)DeleteStoredataClicked:(UIButton *)sender
{
    
   
    
}

- (IBAction)store_editButtonClicked:(id)sender
{
     NSString *selectQuery=[NSString stringWithFormat:@"select store_name,store_id,email, phonenumber,street,city,postal,country,state,defaulttax,discount,currency, created_timestamp,modified_timestamp,server_local,unique_id from store_details"];
    NSMutableArray *storeDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storeDataArray];
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    
   
    NSInteger selected=but.tag-1;
    NSDictionary *dict;
    dict=[storeDataArray objectAtIndex:selected];
    NSString *store_nameStr=[dict objectForKey:@"store_name"];
    NSString *store_idstr=[dict objectForKey:@"store_id"];
    NSString *store_email=[dict objectForKey:@"email"];
    NSString *store_number=[dict objectForKey:@"phonenumber"];
    NSString *store_street=[dict objectForKey:@"street"];
    NSString *store_city=[dict objectForKey:@"city"];
    NSString *store_postal=[dict objectForKey:@"postal"];
    NSString *store_country=[dict objectForKey:@"country"];
    NSString *store_state=[dict objectForKey:@"state"];
    NSString *store_tax=[dict objectForKey:@"defaulttax"];
    NSString *store_discount=[dict objectForKey:@"discount"];
    NSString *store_currency=[dict objectForKey:@"currency"];
   
    //NSLog(@"%@",store_tax);
    
    changeStorename=store_nameStr;
    Changestoreid=store_idstr;
    changeEmail=store_email;
    Changenumber=store_number;
    changestreet=store_street;
    changeCity=store_city;
    changePostal=store_postal;
    changeCountrty=store_country;
    Changestate=store_state;
    Changetax=store_tax;
    ChangeDiscount=store_discount;
    Changecurrency=store_currency;
    
    
    if (!EditStoredataBackView)
    EditStoredataBackView=[[UIView alloc]init];
    if (isLandScope) {
        EditStoredataBackView.frame=CGRectMake(0, 0, 1024, 768);
    }else{
        
        EditStoredataBackView.frame=CGRectMake(0, 0, 768, 1024);
    }
    [EditStoredataBackView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:EditStoredataBackView];
    
     if (!EditsoreView)
    EditsoreView =[[UIScrollView alloc]init];
    EditsoreView.frame=CGRectMake(20, 100, EditStoredataBackView.frame.size.width-40, EditStoredataBackView.frame.size.height-200);
    EditsoreView.contentSize=CGSizeMake(EditStoredataBackView.frame.size.width-100,EditStoredataBackView.frame.size.height+300);
    [EditsoreView setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    [EditsoreView.layer setBorderWidth:2.0];
    [EditsoreView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    //EditsoreView.layer.cornerRadius=8;
    [EditStoredataBackView addSubview:EditsoreView];
    
    NSArray *labelArray;
    CGFloat Editlabelwidth=(EditsoreView.frame.size.width/4);
    int k=20;
    for (int i=0; i< 9; i++)
    {
        EditFieldLbl=[[UILabel alloc] init];
        EditFieldLbl.frame=CGRectMake(Editlabelwidth-30, k, Editlabelwidth+60, 40);
        
        EditFieldLbl.tag=i+100;
        [EditFieldLbl setFont:[UIFont systemFontOfSize:25.0f]];
        [EditFieldLbl setBackgroundColor:[UIColor clearColor]];
        [EditFieldLbl setTextColor:[UIColor whiteColor]];
         if (!labelArray)
        labelArray=[[NSArray alloc] initWithObjects:@"Store Name* ",@"Store Id* ",@"Store Email",@"Contact Number ",@"Street ",@"City",@"Zip/Postal Code",@"Country",@"State",@" ",nil];
        [EditFieldLbl setText:[labelArray objectAtIndex:i]];
        [EditFieldLbl setTextAlignment:NSTextAlignmentLeft];
        [EditsoreView addSubview:EditFieldLbl];
        
        EditdataField=[[UITextField alloc] init];
        //[nameTextfield setBorderStyle:UITextBorderStyleRoundedRect];
        EditdataField.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, k,Editlabelwidth, 40);
        EditdataField.delegate=self;
        EditdataField.tag=i+100;
        
        UIView *paddingview=[[UIView alloc] initWithFrame:CGRectMake(5, 0, 5, 20)];
        // // //NSLog(@"%f",dataField.frame.origin.y);
        EditdataField.leftView = paddingview;
        EditdataField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
        EditdataField.leftViewMode = UITextFieldViewModeAlways;
        [EditdataField setBackground:[UIImage imageNamed:@"addinputtextfield.png"]];
        [EditdataField setAutocorrectionType:UITextAutocorrectionTypeNo];
        [EditdataField addTarget:self action:@selector(EditdatatextfieldClicked:) forControlEvents:UIControlEventEditingDidEnd];
        
        if (EditdataField.tag == 100)
        {
            EditdataField.text=store_nameStr;
            
        }
        if (EditdataField.tag == 101)
        {
            EditdataField.text=store_idstr;
            
        }
        if (EditdataField.tag == 102)
        {
            EditdataField.text=store_email;
        }
        if (EditdataField.tag == 103)
        {
            EditdataField.text=store_number;
        }
        if (EditdataField.tag == 104)
        {
            EditdataField.text=store_street;
        }
        if (EditdataField.tag == 105)
        {
            EditdataField.text=store_city;
        }
        if (EditdataField.tag == 106)
        {
            EditdataField.text=store_postal;
        }
        if (EditdataField.tag == 107)
        {
            EditdataField.text=store_country;
        }
        if (EditdataField.tag == 108)
        {
            EditdataField.text=store_state;
        }
        
        if (EditdataField.tag == 109)
        {
            [EditdataField setBackground:[UIImage imageNamed:@" "]];
            
        }
        [EditsoreView addSubview:EditdataField];
        
        paddingview=nil;
        
        
        k=k+60;
    }
    //// //NSLog(@"%d",k);
     if (!EditdefaluttaxLbl)
    EditdefaluttaxLbl=[[UILabel alloc] init];
    EditdefaluttaxLbl.frame=CGRectMake(Editlabelwidth-30,560,Editlabelwidth+60, 40);
    [EditdefaluttaxLbl setFont:[UIFont systemFontOfSize:25.0f]];
    [EditdefaluttaxLbl setBackgroundColor:[UIColor clearColor]];
    [EditdefaluttaxLbl setTextColor:[UIColor whiteColor]];
    [EditdefaluttaxLbl setText:@"Default Tax"];
    [EditdefaluttaxLbl setTextAlignment:NSTextAlignmentLeft];
    [EditsoreView addSubview:EditdefaluttaxLbl];
    if (!EditDefaulttaxBtn)
    EditDefaulttaxBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    EditDefaulttaxBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,560, Editlabelwidth, 40);
    
    [EditDefaulttaxBtn setTag:1];
    [EditDefaulttaxBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [EditDefaulttaxBtn setTitle:store_tax forState:UIControlStateNormal];
    EditDefaulttaxBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [EditDefaulttaxBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [EditDefaulttaxBtn addTarget:self action:@selector(EditDefaulttaxClick) forControlEvents:UIControlEventTouchUpInside];
    [EditsoreView addSubview:EditDefaulttaxBtn];
    if (!Editsubtotallbl)
    Editsubtotallbl=[[UILabel alloc] init];
    Editsubtotallbl.frame=CGRectMake(Editlabelwidth-30, 620, Editlabelwidth+50, 40);
    [Editsubtotallbl setFont:[UIFont systemFontOfSize:25.0f]];
    [Editsubtotallbl setBackgroundColor:[UIColor clearColor]];
    [Editsubtotallbl setTextColor:[UIColor whiteColor]];
    [Editsubtotallbl setText:@"Subtotal Discount"];
    [Editsubtotallbl setTextAlignment:NSTextAlignmentLeft];
    [EditsoreView addSubview:Editsubtotallbl];
    if (!EditsubtotalBtn)
    EditsubtotalBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    EditsubtotalBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width+10,620, 40, 40);
    
    [EditsubtotalBtn setTag:1];
    if ([store_discount isEqualToString:@"true"])
    {
        [EditsubtotalBtn setSelected:YES];
        //[dbMgr  setStoreDiscount:@"true"];
        EditSubtotalStr=@"true";
    }
    else  if ([store_discount isEqualToString:@"false"])
    {
        [EditsubtotalBtn setSelected:NO];
        //[dbMgr  setStoreDiscount:@"false"];
        EditSubtotalStr=@"false";
    }
    [EditsubtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-off.png"] forState:UIControlStateNormal];
    [EditsubtotalBtn setBackgroundImage:[UIImage imageNamed:@"checkbox-on.png"] forState:UIControlStateSelected];
    
    EditsubtotalBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [EditsubtotalBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [EditsubtotalBtn addTarget:self action:@selector(Editsubtotalclicked) forControlEvents:UIControlEventTouchUpInside];
    
    [EditsoreView addSubview:EditsubtotalBtn];
    if (!Editcurrencylbl)
    Editcurrencylbl=[[UILabel alloc] init];
    Editcurrencylbl.frame=CGRectMake(Editlabelwidth-30, 680, Editlabelwidth+60, 40);
    [Editcurrencylbl setFont:[UIFont systemFontOfSize:25.0f]];
    [Editcurrencylbl setBackgroundColor:[UIColor clearColor]];
    [Editcurrencylbl setTextColor:[UIColor whiteColor]];
    [Editcurrencylbl setText:@"Currency"];
    [Editcurrencylbl setTextAlignment:NSTextAlignmentLeft];
    [EditsoreView addSubview:Editcurrencylbl];
    if (!EditcurrencyBtn)
    EditcurrencyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    EditcurrencyBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,680, Editlabelwidth, 40);
    
    [EditcurrencyBtn setTag:1];
    [EditcurrencyBtn setBackgroundImage:[UIImage imageNamed:@"drop-down-icon.png"] forState:UIControlStateNormal];
    [EditcurrencyBtn setTitle:store_currency forState:UIControlStateNormal];
    EditcurrencyBtn.titleLabel.font = [UIFont systemFontOfSize:25.0f];
    [EditcurrencyBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [EditcurrencyBtn addTarget:self action:@selector(EditcurrencybtnClicked) forControlEvents:UIControlEventTouchUpInside];
    [EditsoreView addSubview:EditcurrencyBtn];
    if (!EditsavestoreDataBtn)
    EditsavestoreDataBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    EditsavestoreDataBtn.frame=CGRectMake(Editlabelwidth+60,760,100, 30);
    [EditsavestoreDataBtn addTarget:self action:@selector(SaveChangeStoredataCliked) forControlEvents:UIControlEventTouchUpInside];
    
    //[SaveTaxButton setTitle:@"Save" forState:UIControlStateNormal];
    [EditsavestoreDataBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [EditsavestoreDataBtn setBackgroundImage:[UIImage imageNamed:@"savegreenbutton.png"] forState:UIControlStateNormal];
    [EditsoreView addSubview:EditsavestoreDataBtn];
     if (!EditresetStoreDatabtn)
    EditresetStoreDatabtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    
    EditresetStoreDatabtn.frame=CGRectMake(Editlabelwidth+220, 760, 100, 30);
    [EditresetStoreDatabtn addTarget:self action:@selector(ResetChangestoredataClicked) forControlEvents:UIControlEventTouchUpInside];
    [EditresetStoreDatabtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [EditresetStoreDatabtn setBackgroundImage:[UIImage imageNamed:@"cancelgreenbutton.png"] forState:UIControlStateNormal];
    
    [EditsoreView addSubview:EditresetStoreDatabtn];
     if (!edittaxesTable)
    edittaxesTable = [[UITableView alloc] initWithFrame:CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100) style:UITableViewStylePlain];
    edittaxesTable.backgroundColor=[UIColor whiteColor];
    edittaxesTable.delegate = self;
    edittaxesTable.dataSource = self;
    edittaxesTable.scrollEnabled = YES;
    edittaxesTable.hidden=YES;
    [edittaxesTable.layer setBorderWidth: 1.0];
    [edittaxesTable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [EditsoreView addSubview:edittaxesTable];
    if (!editcurrencytable)
    editcurrencytable = [[UITableView alloc] initWithFrame:CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100) style:UITableViewStylePlain];
    editcurrencytable.backgroundColor=[UIColor whiteColor];
    editcurrencytable.delegate = self;
    editcurrencytable.dataSource = self;
    editcurrencytable.scrollEnabled = YES;
    editcurrencytable.hidden=YES;
    [editcurrencytable.layer setBorderWidth: 1.0];
    [editcurrencytable.layer setBorderColor:[[UIColor grayColor] CGColor]];
    [EditsoreView addSubview:editcurrencytable];
    

}
- (IBAction)store_viewButtonClicked:(id)sender
{
    NSString *selectQuery=[NSString stringWithFormat:@"select store_name,store_id,email, phonenumber,street,city,postal,country,state,defaulttax,discount,currency,unique_id from store_details"];
    NSMutableArray *storeDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storeDataArray];
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    
    NSInteger selected=but.tag-1;
    NSDictionary *dict;
    dict=[storeDataArray  objectAtIndex:selected];
    if (!AllkeysArray)
    {
    AllkeysArray=[[NSArray alloc]init];
    AllvaluesArray=[[NSArray alloc]init];
    }
    
    AllkeysArray=[dict allKeys];
    AllvaluesArray=[dict allValues];
    if (!viewStoredataBackView)
    viewStoredataBackView=[[UIView alloc]init];
    if (isLandScope) {
        viewStoredataBackView.frame=CGRectMake(0, 0, 1024, 768);
    }else{
        
        viewStoredataBackView.frame=CGRectMake(0, 0, 768, 1024);
    }
    [viewStoredataBackView setBackgroundColor:[UIColor colorWithRed:10.0f/255.0f green:10.0f/255.0f blue:10.0f/255.0f alpha:0.7f/1.0f]];
    [self.view addSubview:viewStoredataBackView];
     if (!ViewStoredataTable)
    ViewStoredataTable =[[UITableView alloc]init];
    ViewStoredataTable.frame=CGRectMake(100, 100, viewStoredataBackView.frame.size.width-200, [AllvaluesArray count]*40);
    ViewStoredataTable.delegate=self;
    ViewStoredataTable.dataSource=self;
    //[ViewStoredataTable setBackgroundColor:[UIColor colorWithRed:0.0f green:74.0f/255.0f blue:132.0f/255.0f alpha:1.0f]];
    
    ViewStoredataTable.layer.cornerRadius=8;
    [viewStoredataBackView addSubview:ViewStoredataTable];
}
- (IBAction)store_deleteButtonClicked:(id)sender{
    UIButton *but =sender;
    // //NSLog(@"EditButton %d",but.tag);
    
    selectedstore=but.tag-1;
    deleteStoreAlert=[[UIAlertView alloc]initWithTitle:@"Delete" message:@"Are you sure you want delete the Store Data" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:@"cancel", nil];
    [deleteStoreAlert show];
}

-(void)EditstoredataClicked:(UIButton *)sender
{
    
    
}
-(void)EditdatatextfieldClicked:(UITextField *)sender
{
    NSInteger selected=sender.tag;
    
    if (selected == 100)
    {
        
        changeStorename=sender.text;
    }
    if (selected == 101)
    {
        Changestoreid=sender.text;
    }
    if (selected == 102)
    {
        changeEmail=sender.text;
    }
    if (selected == 103)
    {
        
        Changenumber=sender.text;
    }
    if (selected == 104)
    {
        
        changestreet=sender.text;
    }
    if (selected == 105)
    {
        changeCity=sender.text;
    }
    if (selected == 106)
    {
        changePostal=sender.text;
    }
    if (selected == 107)
    {
        
        changeCountrty=sender.text;
    }
    if (selected == 108)
    {
        Changestate=sender.text;
    }

}
-(void)SaveChangeStoredataCliked
{
    NSString *selectQuery=[NSString stringWithFormat:@"select store_id from store_details"];
    NSMutableArray *storesArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storesArray];
    
    storeIDSArray=[[NSMutableArray alloc]init];
    @autoreleasepool {
        for (NSDictionary *myDict in storesArray)
        {
            NSString *storeIDStr=[myDict objectForKey:@"store_id"];
            
            [storeIDSArray addObject:storeIDStr];
        }
    }
   
    Changecurrency=[NSString stringWithFormat:@"%@", EditcurrencyBtn.titleLabel.text];
    Changetax=[NSString stringWithFormat:@"%@", EditDefaulttaxBtn.titleLabel.text];
    
    NSString *updateSQL =@"UPDATE store_details SET store_name =?,store_id =?,email=?,phonenumber=?,street=?,city=?,postal=?,country=?,state=?,defaulttax=?,discount=?,currency=? WHERE store_id =?";
    
    NSMutableArray *storeupdateArray=[[NSMutableArray alloc]initWithObjects:changeStorename,Changestoreid,changeEmail,Changenumber,changestreet,changeCity,changePostal,changeCountrty,Changestate,Changetax,EditSubtotalStr,Changecurrency,Changestoreid, nil];
    [[DataBaseManager dataBaseManager]executeRecordsWithQuery:updateSQL withArguments:storeupdateArray];
    
    NSString *selectQuery2=[NSString stringWithFormat:@"select store_name,store_id,email,phonenumber,street,city,postal,country,state,defaulttax,discount,currency,unique_id,created_timestamp,modified_timestamp,server_local from store_details where store_id='%@'",storeid];
    NSMutableArray *storeDataArray=[[NSMutableArray alloc]init];
    [[DataBaseManager dataBaseManager]execute:selectQuery2 resultsArray:storeDataArray];
    
    NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
    [CategoryDict setObject:storeDataArray forKey:@"fields"];
    NSDictionary *jsonDict = [NSDictionary dictionaryWithDictionary:CategoryDict];
    
    
    NSError *err;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:&err];
    
    NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
    if(![generalDataObject  connectedToInternet])
    {
        
        NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
        
        NSMutableArray *pendingsArray=[[NSMutableArray alloc]initWithObjects:@"UPDATE",[generalDataObject  userID],@"saveinfo.php?",str,@"store_details",[generalDataObject getsystemDatetime], nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:pendingsArray];

    }
    else if([generalDataObject  connectedToInternet])
    {
        
        if ([[generalDataObject  OriginalbaseURLstr] length]>0)
        {
        
        // //NSLog(@"%@",str);
        NSString *string=[NSString stringWithFormat:@"%@saveinfo.php?tablename=store_details&systemtime=%@&userid=%@&sessionid=%@&data=%@&update=true",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  genRandStringLength:20],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        
        // //NSLog(@"%@",str);
        
        NSURL *url=[NSURL URLWithString:string];
        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
        // //NSLog(@"%@",url);
        
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
        
        
        
        StoreConnection = [NSURLConnection connectionWithRequest:request delegate:self];
        
        [StoreConnection start];
        }
    }
        [self getStoreDataMethod];
    
    NSArray *EditsoreViewArray = EditsoreView.subviews;
    for (int i = 0; i<[EditsoreViewArray count]; i++) {
        UIView *vi =[EditsoreViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *EditStoredataBackViewArray = EditStoredataBackView.subviews;
    for (int i = 0; i<[EditStoredataBackViewArray count]; i++) {
        UIView *vi =[EditStoredataBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [EditsoreView removeFromSuperview],[EditStoredataBackView removeFromSuperview];
    [editstoresTable reloadData];
   
    
    
}
-(void)ResetChangestoredataClicked
{
    NSArray *EditsoreViewArray = EditsoreView.subviews;
    for (int i = 0; i<[EditsoreViewArray count]; i++) {
        UIView *vi =[EditsoreViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *EditStoredataBackViewArray = EditStoredataBackView.subviews;
    for (int i = 0; i<[EditStoredataBackViewArray count]; i++) {
        UIView *vi =[EditStoredataBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [EditsoreView removeFromSuperview],[EditStoredataBackView removeFromSuperview];
   
    
}
-(void)Editsubtotalclicked
{
    if (EditsubtotalBtn.selected)
    {
        [EditsubtotalBtn setSelected:NO];
        
        EditSubtotalStr=@"false";
    }
    else if(!EditsubtotalBtn.selected)
    {
        [EditsubtotalBtn setSelected:YES];
        EditSubtotalStr=@"true";
        
    }
}
-(void)EditDefaulttaxClick
{
    
    if (edittaxesTable.hidden==1)
    {
        
        edittaxesTable.hidden=NO;
        
    }
    else if (edittaxesTable.hidden==0)
    {
        [edittaxesTable setHidden:YES];
    
    }
}
-(void)EditcurrencybtnClicked
{
    if (editcurrencytable.hidden==1)
    {
        
        editcurrencytable.hidden=NO;
        
        
    }
    else if (editcurrencytable.hidden==0)
    {
        [editcurrencytable setHidden:YES];
        
        
        
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
{
    // //NSLog(@"%d",selectedstore);
    if (alertView==deleteStoreAlert && buttonIndex==0){
        
        
        NSString *selectedid=[storeIDSArray objectAtIndex:selectedstore];
       
        // NSString *selectQuery2=[NSString stringWithFormat:@"select * from store_details where store_id='%@'",selectedid];
        NSString *selectQuery=[NSString stringWithFormat:@"select unique_id from store_details where store_id='%@'",selectedid];
        NSMutableArray *storeDataArray=[[NSMutableArray alloc]init];
        [[DataBaseManager dataBaseManager]execute:selectQuery resultsArray:storeDataArray];
        NSMutableArray *storeuniqueidsArray=[[NSMutableArray alloc]init];
        
        for (NSDictionary *Dict in storeDataArray) {
            
            [storeuniqueidsArray addObject:[Dict objectForKey:@"unique_id"]];
        }
        NSMutableDictionary *CategoryDict=[[NSMutableDictionary alloc]init];
        [CategoryDict setObject:storeDataArray forKey:@"fields"];
            NSError *err;
        
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:storeuniqueidsArray options:kNilOptions error:&err];
        
        NSString *str=[[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        if(![generalDataObject  connectedToInternet]){
    
            
            NSString *insertSQL =@"insert into pending_queries (query_type,user_id,page_url,parameters,table_name,current_time) values(?,?,?,?,?,?)";
            
            NSMutableArray *pendingsArray=[[NSMutableArray alloc]initWithObjects:@"DELETE",[generalDataObject  userID],@"deleteinfo.php?",str,@"store_details",[generalDataObject getsystemDatetime], nil];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertSQL withArguments:pendingsArray];
            
        }
        else if([generalDataObject  connectedToInternet]){
            
            
            if ([[generalDataObject  OriginalbaseURLstr] length]>0)
            {
            // //NSLog(@"%@",str);
            NSString *string=[NSString stringWithFormat:@"%@deleteinfo.php?tablename=store_details&systemtime=%@&userid=%@&sessionid=%@&unique_ids=%@",[generalDataObject  OriginalbaseURLstr],[[generalDataObject getsystemDatetime] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],[generalDataObject  userID],[generalDataObject  genRandStringLength:20],[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
            
            // //NSLog(@"%@",str);
            
            NSURL *url=[NSURL URLWithString:string];
            NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
            // //NSLog(@"%@",url);
            
            [request setHTTPMethod:@"POST"];
            [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
            //[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
            
            
            
            StoreConnection = [NSURLConnection connectionWithRequest:request delegate:self];
            
            [StoreConnection start];
            }
        }
        NSString *deleteQuery =@"DELETE FROM store_details WHERE store_id=?";
        NSMutableArray *deleteArray=[[NSMutableArray alloc]initWithObjects:selectedid, nil];
        [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deleteQuery withArguments:deleteArray];
       
          [self getStoreDataMethod];
        [editstoresTable reloadData];

    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    
    if (connection == StoreConnection)
    {
        StoreResponseData = [[NSMutableData alloc] init];
    }
    
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    
    if (connection == StoreConnection)
    {
        [StoreResponseData appendData:data];
    }
    
    
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (connection == StoreConnection)
    {
        
        NSString *responseStr = [[NSString alloc] initWithBytes:[StoreResponseData mutableBytes] length:[StoreResponseData length] encoding:NSUTF8StringEncoding];
        
        NSError *error;
        NSMutableDictionary *dataDict;
        NSData *jsonData = [responseStr dataUsingEncoding:NSUTF8StringEncoding];
        dataDict =[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
        // //NSLog(@"%@",dataDict);
        
        NSMutableArray *deleteArray=[dataDict objectForKey:@"delete-queries"];
        NSMutableArray *insertsArray=[dataDict objectForKey:@"insert-queries"];
        
        NSMutableArray *deletesArray;
        for (int i=0; i<[deleteArray count]; i++)
        {
            NSString *foo=[deleteArray objectAtIndex:i];
            NSString* bar = [foo stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* deletestr = [bar stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:deletestr withArguments:deletesArray];
            
            NSString *foo2=[insertsArray objectAtIndex:i];
            NSString* bar2 = [foo2 stringByReplacingOccurrencesOfString:@"'" withString:@"\""];
            NSString* insertstr = [bar2 stringByReplacingOccurrencesOfString:@"\\\"" withString:@"'"];
            
            [[DataBaseManager dataBaseManager]executeRecordsWithQuery:insertstr withArguments:deletesArray];
        }
        
      
    }
}
-(void)updateUI
{
    
    if (isLandScope)
    {
        
        CGFloat width,height;
        
        width=1024;
        height=748;
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        
        
        //  sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        //sidemenu.hidden=YES;
        
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        // mainview.frame=CGRectMake(sidemenu.frame.size.width+10,0,width-(sidemenu.frame.size.width+20),height-150);
        mainview.frame=CGRectMake(20,60,width-40,height-200);
        
        [backgroundcolorview addSubview:mainview];
        [menubutton setFrame:CGRectMake(0,0,50,50)];
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        // add stores view
        AddstoresBackview.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
       
        addstoresView.frame=CGRectMake(10, 10, AddstoresBackview.frame.size.width-20, AddstoresBackview.frame.size.height-20);
         addstoresView.contentSize=CGSizeMake(AddstoresBackview.frame.size.width-20,AddstoresBackview.frame.size.height+400);
        CGFloat labelwidth=(addstoresView.frame.size.width/4);
        int b=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[addstoresView viewWithTag:i+100];
            mylabel.frame=CGRectMake(211, b, labelwidth+60, 40);
            [addstoresView addSubview:mylabel];
            //// //NSLog(@"%f",mylabel.frame.origin.x);
        
            b=b+60;
        }
        int j=20;
        for (int i=0; i< 5; i++)
        {
            UITextField *mytextfield=(UITextField *)[addstoresView viewWithTag:i+100];
            mytextfield.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, j,labelwidth, 40);
            [addstoresView addSubview:mytextfield];
            
            
            j=j+60;
        }
        
        //// //NSLog(@"%d",k);
        
        citytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 320,labelwidth, 40);
        
        postalTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 380,labelwidth, 40);
        CountrytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 440,labelwidth, 40);
        
        stateTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 500,labelwidth, 40);
        citysTable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 360,labelwidth,100);
        countrysTable.frame= CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 480,labelwidth,100);
        
        statesTable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 400,labelwidth,100);
        defaluttaxLbl.frame=CGRectMake(labelwidth-30,560,labelwidth+60, 40);
        DefaulttaxBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,560, labelwidth, 40);
        subtotallbl.frame=CGRectMake(labelwidth-30, 620, labelwidth+50, 40);
        subtotalBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width+10,620, 40, 40);
        currencylbl.frame=CGRectMake(labelwidth-30, 680, labelwidth+60, 40);
        currencyBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,680, labelwidth, 40);
        savestoreDataBtn.frame=CGRectMake(labelwidth+100,760,100, 30);
        
        resetStoreDatabtn.frame=CGRectMake(labelwidth+260, 760, 100, 30);
        taxesTable .frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100);
        currencytable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100);
        
      
        
        //edit store view
        
        editStoresView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        editstoresTable.frame=CGRectMake(10, 10, editStoresView.frame.size.width-20, editStoresView.frame.size.height-20);
        
        viewStoredataBackView.frame=CGRectMake(0, 0, 1024, 768);
       ViewStoredataTable.frame=CGRectMake(100, 100, viewStoredataBackView.frame.size.width-200, [AllvaluesArray count]*40);
        
        //edit storedata view
        EditStoredataBackView.frame=CGRectMake(0, 0, 1024, 768);
        EditsoreView.frame=CGRectMake(20, 100, EditStoredataBackView.frame.size.width-40, EditStoredataBackView.frame.size.height-200);
        EditsoreView.contentSize=CGSizeMake(EditStoredataBackView.frame.size.width-100,EditStoredataBackView.frame.size.height+300);
        CGFloat Editlabelwidth=(EditsoreView.frame.size.width/4);
        int a=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[EditsoreView viewWithTag:i+100];
            mylabel.frame=CGRectMake(Editlabelwidth, a, Editlabelwidth+60, 40);
            [EditsoreView addSubview:mylabel];
            //// //NSLog(@"%f",mylabel.frame.origin.x);
            UITextField *mytextfield=(UITextField *)[EditsoreView viewWithTag:i+100];
            mytextfield.frame=CGRectMake(Editlabelwidth+mylabel.frame.size.width-20, a,Editlabelwidth, 40);
            [EditsoreView addSubview:mytextfield];
            a=a+60;
        }
        EditdefaluttaxLbl.frame=CGRectMake(Editlabelwidth-30,560,Editlabelwidth+60, 40);
        EditDefaulttaxBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,560, Editlabelwidth, 40);
        
        Editsubtotallbl.frame=CGRectMake(Editlabelwidth-30, 620, Editlabelwidth+50, 40);
        EditsubtotalBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width+10,620, 40, 40);
        
        Editcurrencylbl.frame=CGRectMake(Editlabelwidth-30, 680, Editlabelwidth+60, 40);
        EditcurrencyBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,680, Editlabelwidth, 40);
        
        EditsavestoreDataBtn.frame=CGRectMake(Editlabelwidth+60,760,100, 30);
        EditresetStoreDatabtn.frame=CGRectMake(Editlabelwidth+220, 760, 100, 30);
        
        edittaxesTable .frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100);
        editcurrencytable.frame = CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100);
        
    }
    else
    {
        CGFloat width,height;
        height=1004;
        width=768;
        // //NSLog(@" %f,%f",width,height);
        
        
        backgroundcolorview.frame=CGRectMake(0,y,width,height-100);
        navBar.frame=CGRectMake(0, 0,width , 50.0);
        
        [logoBtn setFrame:CGRectMake(60,0,250,50)];
        
        sationLbl.frame=CGRectMake(navBar.frame.size.width-280, 5,100, 40);
        EmpIdlbl.frame=CGRectMake(navBar.frame.size.width-193, 5,150, 40);
        Timelbl.frame=CGRectMake(navBar.frame.size.width-62, 6,80, 40);
        
        //sidemenu.frame=CGRectMake(0, 1,170 ,height-150);
        // sidemenu.hidden=YES;
        [categorybutton setFrame:CGRectMake(0.0,p,170,40)];
        mainview.frame=CGRectMake(20,60,width-40,height-200);
        [menubutton setFrame:CGRectMake(0,0,50,50)];
        
        maintoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        //downtoolBar.frame = CGRectMake(0, 0, mainview.frame.size.width, 40);
        
        logoimageview.frame=CGRectMake(50, (backgroundcolorview.frame.size.height)+5+y,(height-(backgroundcolorview.frame.size.height)-30), (height-(backgroundcolorview.frame.size.height)-30));
        
        [helpiconButton setFrame:CGRectMake(width-180,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        
        [logouticonButton setFrame:CGRectMake(width-100,(backgroundcolorview.frame.size.height)+10+y,70,70)];
        
        // add stores view
        AddstoresBackview.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        
        addstoresView.frame=CGRectMake(10, 10, AddstoresBackview.frame.size.width-20, AddstoresBackview.frame.size.height-20);
        addstoresView.contentSize=CGSizeMake(AddstoresBackview.frame.size.width-20,AddstoresBackview.frame.size.height+350);
        CGFloat labelwidth=(addstoresView.frame.size.width/4);
        int b=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[addstoresView viewWithTag:i+100];
            mylabel.frame=CGRectMake(labelwidth, b, labelwidth+60, 40);
            [addstoresView addSubview:mylabel];
            //// //NSLog(@"%f",mylabel.frame.origin.x);
           
            b=b+60;
        }
        int j=20;
        for (int i=0; i< 5; i++)
        {
            UITextField *mytextfield=(UITextField *)[addstoresView viewWithTag:i+100];
            mytextfield.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, j,labelwidth, 40);
            [addstoresView addSubview:mytextfield];
            
            
            j=j+60;
        }
        
        //// //NSLog(@"%d",k);
    
        citytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 320,labelwidth, 40);
      
        postalTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 380,labelwidth, 40);
        CountrytextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 440,labelwidth, 40);
      
        stateTextField.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 500,labelwidth, 40);
        citysTable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 360,labelwidth,100);
        countrysTable.frame= CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 480,labelwidth,100);
        statesTable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 400,labelwidth,100);
        
        defaluttaxLbl.frame=CGRectMake(labelwidth-5,560,labelwidth+60, 40);
        DefaulttaxBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,560, labelwidth, 40);
        subtotallbl.frame=CGRectMake(labelwidth-5, 620, labelwidth+50, 40);
        subtotalBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width+10,620, 40, 40);
        currencylbl.frame=CGRectMake(labelwidth-5, 680, labelwidth+60, 40);
        currencyBtn.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20,680, labelwidth, 40);
        savestoreDataBtn.frame=CGRectMake(labelwidth+60,760,100, 30);
        resetStoreDatabtn.frame=CGRectMake(labelwidth+220, 760, 100, 30);
        taxesTable .frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100);
        currencytable.frame=CGRectMake(labelwidth+fieldslbl.frame.size.width-20, 601,labelwidth,100);
        
        
        //edit store view
        
        editStoresView.frame=CGRectMake(10, maintoolBar.frame.size.height+10, (mainview.frame.size.width)-20, (mainview.frame.size.height)-(maintoolBar.frame.size.height+20));
        editstoresTable.frame=CGRectMake(10, 10, editStoresView.frame.size.width-20, editStoresView.frame.size.height-20);
        
        viewStoredataBackView.frame=CGRectMake(0, 0, 768, 1024);
    ViewStoredataTable.frame=CGRectMake(100, 100, viewStoredataBackView.frame.size.width-200, [AllvaluesArray count]*40);
        
        //edit storedata view
        EditStoredataBackView.frame=CGRectMake(0, 0, 768, 1024);
    EditsoreView.frame=CGRectMake(20, 100, EditStoredataBackView.frame.size.width-40, EditStoredataBackView.frame.size.height-200);
    EditsoreView.contentSize=CGSizeMake(EditStoredataBackView.frame.size.width-100,EditStoredataBackView.frame.size.height+300);
       CGFloat Editlabelwidth=(EditsoreView.frame.size.width/4);
        int a=20;
        for (int i=0; i<9; i++)
        {
            UILabel *mylabel=(UILabel *)[EditsoreView viewWithTag:i+100];
            mylabel.frame=CGRectMake(Editlabelwidth, a, Editlabelwidth+60, 40);
            [EditsoreView addSubview:mylabel];
            //// //NSLog(@"%f",mylabel.frame.origin.x);
            UITextField *mytextfield=(UITextField *)[EditsoreView viewWithTag:i+100];
            mytextfield.frame=CGRectMake(Editlabelwidth+mylabel.frame.size.width-20, a,Editlabelwidth, 40);
            [EditsoreView addSubview:mytextfield];
            a=a+60;
        }
    EditdefaluttaxLbl.frame=CGRectMake(Editlabelwidth-30,560,Editlabelwidth+60, 40);
    EditDefaulttaxBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,560, Editlabelwidth, 40);
    
       Editsubtotallbl.frame=CGRectMake(Editlabelwidth-30, 620, Editlabelwidth+50, 40);
    EditsubtotalBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width+10,620, 40, 40);
    
      Editcurrencylbl.frame=CGRectMake(Editlabelwidth-30, 680, Editlabelwidth+60, 40);
    EditcurrencyBtn.frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20,680, Editlabelwidth, 40);
    
    EditsavestoreDataBtn.frame=CGRectMake(Editlabelwidth+60,760,100, 30);
    EditresetStoreDatabtn.frame=CGRectMake(Editlabelwidth+220, 760, 100, 30);

    edittaxesTable .frame=CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100);
       editcurrencytable.frame = CGRectMake(Editlabelwidth+EditFieldLbl.frame.size.width-20, 601,Editlabelwidth,100);
    
        
    }

}

-(void)menuclicked
{
    if (menuslected == false)
    {
        
        // //NSLog(@"called");
        // //NSLog(@"%d",menuslected);
        menuslected=YES;
        logoBtn.hidden=YES;
        
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(0,0);
        //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
        //sidemenu.hidden=NO;
       // [UIView commitAnimations];
        [backgroundcolorview addSubview:sidemenu];
        
        //[UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:0.9f];
        menubutton.transform = CGAffineTransformMakeTranslation(180,0);
        
        menubutton.transform = CGAffineTransformRotate( menubutton.transform, - M_PI);
        //[UIView commitAnimations];
        //[UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        
        
    }else
    {
        
        logoBtn.hidden=NO;
        menuslected=NO;
        
        //[UIView beginAnimations:nil context:NULL];
       // [UIView setAnimationDuration:1.0f];
        sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
        
        //[UIView commitAnimations];
       
       // [UIView beginAnimations:nil context:NULL];
        //[UIView setAnimationDuration:1.0f];
        menubutton.transform = CGAffineTransformMakeTranslation(0,0);
        
        
        //[UIView commitAnimations];
       //[UIView beginAnimations:nil context:NULL];
///[UIView setAnimationDuration:1.0f];
        
    }
    
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    
    logoBtn.hidden=NO;
//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.8f];
    mainview.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    //[UIView commitAnimations];
   // [UIView beginAnimations:nil context:NULL];
   // [UIView setAnimationDuration:0.8f];
    sidemenu.transform = CGAffineTransformMakeTranslation(-250,0);
    //[SideMenuView setBackgroundColor:[UIColor whiteColor]];
    
    //[UIView commitAnimations];
   // [UIView commitAnimations];
    //[UIView beginAnimations:nil context:NULL];
    //[UIView setAnimationDuration:0.0f];
    menubutton.transform = CGAffineTransformMakeTranslation(0,0);
    
    
    //[UIView commitAnimations];
    //[UIView beginAnimations:nil context:NULL];
    //[UIView setAnimationDuration:0.0f];
    menuslected=NO;
}

-(void)helpiconclicked
{
    
}
-(void)logoutButtonClicked
{
     [serverSyncClassObject LogoutMethod];
    NSString *updateSQL =@"UPDATE miscellaneous SET userType=?,sessionId=?,userID=?";
    NSMutableArray *misUpdatearray=[[NSMutableArray alloc]initWithObjects:@"",@"",@"", nil];
    [[DataBaseManager dataBaseManager] executeRecordsWithQuery:updateSQL withArguments:misUpdatearray];
    [self.navigationController popToRootViewControllerAnimated:YES];
    [generalDataObject  releasevariable];
    [self releaseViews];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSArray *EditsoreViewArray = EditsoreView.subviews;
    for (int i = 0; i<[EditsoreViewArray count]; i++) {
        UIView *vi =[EditsoreViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *EditStoredataBackViewArray = EditStoredataBackView.subviews;
    for (int i = 0; i<[EditStoredataBackViewArray count]; i++) {
        UIView *vi =[EditStoredataBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [EditsoreView removeFromSuperview],[EditStoredataBackView removeFromSuperview];
    
    
    NSArray *viewStoredataBackViewarray = viewStoredataBackView.subviews;
    for (int i = 0; i<[viewStoredataBackViewarray count]; i++) {
        UIView *vi =[viewStoredataBackViewarray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [viewStoredataBackView removeFromSuperview];
 
     // [addstoresView endEditing:YES];
	//[self touchesBegan:touches withEvent:event];
	//[self finishedSearching];
   
}

/*
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if(textField == EditdataField)
    {
        [textField resignFirstResponder];
        // Show you custom picker here....
        return NO;
    }
    
    
    return YES;
}*/


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == dataField) {
		[dataField resignFirstResponder];
		[dataField becomeFirstResponder];
	}
	else if (textField == dataField) {
		[dataField resignFirstResponder];
    }
    [textField resignFirstResponder];
	BOOL isDone = YES;
	
	if (isDone) {
		[self finishedSearching];
		return YES;
	} else {
		return NO;
	}
}
- (void) finishedSearching {
	[CountrytextField resignFirstResponder];
	countrysTable.hidden = YES;
    
    [stateTextField resignFirstResponder];
    statesTable.hidden=YES;
    [citytextField resignFirstResponder];
    citysTable.hidden=YES;
}

-(void)categotybuttonclicked:(UIButton *)sender
{
    NSArray *viewS = [self.navigationController viewControllers];
    //NSLog(@"nav views %@",viewS);
    NSInteger selectedrow=sender.tag;
    if(selectedrow == 0){
        
        Home *homeview=[[Home alloc]initWithNibName:@"Home" bundle:Nil];
        NSString *returnvalue;
        NSInteger selectedview;
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Home class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        ////NSLog(@"%d",selectedview);
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else{
            
            [self.navigationController pushViewController:homeview animated:NO];
            [self releaseViews];
        }
        
    }else if(selectedrow == 5){
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
                NSString *returnvalue;
                NSInteger selectedview;
                Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:settingsview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            [sender setImage:[UIImage imageNamed:@"settingsactive2.png"] forState:UIControlStateNormal];
            NSString *returnvalue;
            NSInteger selectedview;
            Settings  *settingsview=[[Settings alloc]initWithNibName:@"Settings" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Settings class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                [self.navigationController pushViewController:settingsview animated:NO];
                [self releaseViews];
            }
            
            
        }
        
        
    }else if(selectedrow == 1){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Profile *profileview=[[Profile alloc]initWithNibName:@"Profile" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Profile class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:profileview animated:NO];
                [self releaseViews];
            }
            
        }else{
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
            authalert=nil;
        }
    }else if(selectedrow == 2){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  inventory_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:inventoryview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }
        else
        {
            
            NSString *returnvalue;
            NSInteger selectedview;
            Inventory *inventoryview=[[Inventory alloc]initWithNibName:@"Inventory" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Inventory class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:inventoryview animated:NO];
                [self releaseViews];
            }
        }
    }else if(selectedrow == 3){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  customer_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:customersview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Customers *customersview=[[Customers alloc]initWithNibName:@"Customers" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Customers class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:customersview animated:NO];
                [self releaseViews];
            }
        }
        
    }else if(selectedrow == 4){
        if ([[generalDataObject  userType] isEqualToString:@"admin"])
        {
            NSString *returnvalue;
            NSInteger selectedview;
            Employees *employeesview=[[Employees alloc]initWithNibName:@"Employees" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Employees class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
               [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:employeesview animated:NO];
                [self releaseViews];
            }
            
        }
        else
        {
            UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
            
            [authalert show];
        }
        
    }else if(selectedrow == 6){
        
        if ([[generalDataObject  userType] isEqualToString:@"employee"])
        {
            if ([[generalDataObject  settings_permission] isEqualToString:@"yes"])
            {
                NSString *returnvalue;
                NSInteger selectedview;
                Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
                for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
                {
                    if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                    {
                        returnvalue=@"yes";
                        selectedview=m;
                        break;
                    }
                    
                }
                if([returnvalue isEqualToString:@"yes"])
                {
                    [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                    [self releaseViews];
                }else
                {
                    
                    [self.navigationController pushViewController:reportsview animated:NO];
                    [self releaseViews];
                }
                
            }else{
                
                UIAlertView *authalert=[[UIAlertView alloc]initWithTitle:@"Authentication:" message:@"User not authenticated" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:Nil, nil];
                
                [authalert show];
            }
        }else{
            
            NSString *returnvalue;
            NSInteger selectedview;
            Reports *reportsview=[[Reports alloc]initWithNibName:@"Reports" bundle:Nil];
            for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
            {
                if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Reports class]])
                {
                    returnvalue=@"yes";
                    selectedview=m;
                    break;
                }
                
            }
            if([returnvalue isEqualToString:@"yes"])
            {
                [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
                [self releaseViews];
            }else
            {
                
                [self.navigationController pushViewController:reportsview animated:NO];
                [self releaseViews];
            }
            
        }
        
    }else if(selectedrow == 7){
        NSString *returnvalue;
        NSInteger selectedview;
        Contacts *contactsview=[[Contacts alloc]initWithNibName:@"Contacts" bundle:Nil];
        for (int m=0;m<[self.navigationController.viewControllers count] ; m++)
        {
            if([[self.navigationController.viewControllers objectAtIndex:m] isKindOfClass:[Contacts class]])
            {
                returnvalue=@"yes";
                selectedview=m;
                break;
            }
            
        }
        if([returnvalue isEqualToString:@"yes"])
        {
            [self.navigationController popToViewController:[viewS objectAtIndex:selectedview] animated:YES];
            [self releaseViews];
        }else
        {
            
            [self.navigationController pushViewController:contactsview animated:NO];
            [self releaseViews];
        }

    }
 
    
}

-(void)releaseViews
{
  
    NSArray *mainArray = self.view.subviews;
    for (int i = 0; i<[mainArray count]; i++) {
        UIView *vi =[mainArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *sideArray = sidemenu.subviews;
    for (int i = 0; i<[sideArray count]; i++) {
        UIView *vi =[sideArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *navBarArray = navBar.subviews;
    for (int i = 0; i<[navBarArray count]; i++) {
        UIView *vi =[navBarArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    
    NSArray *addstoresArray = addstoresView.subviews;
    for (int i = 0; i<[addstoresArray count]; i++) {
        UIView *vi =[addstoresArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
   
    [backgroundcolorview removeFromSuperview];
    [sidemenu removeFromSuperview],[mainview removeFromSuperview];
    [AddstoresBackview removeFromSuperview];
    [addstoresView removeFromSuperview];
    sidemenu=nil,mainview=nil,backgroundcolorview=nil;
    categorybutton=nil;
    downtoolBar=nil,maintoolBar=nil;
    [logoimageview removeFromSuperview],[logobackview removeFromSuperview];
    logobackview=nil,logoimageview=nil;
    
    helpiconButton=nil,logouticonButton=nil,menubutton=nil;
    
    AddstoresBtn=nil,EditstoreBtn=nil;
    navBar=nil;
    
    //add stores view
    NSArray *addstoresViewArray = addstoresView.subviews;
    for (int i = 0; i<[addstoresViewArray count]; i++) {
        UIView *vi =[addstoresViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *AddstoresBackviewArray = AddstoresBackview.subviews;
    for (int i = 0; i<[AddstoresBackviewArray count]; i++) {
        UIView *vi =[AddstoresBackviewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [addstoresView removeFromSuperview],[AddstoresBackview removeFromSuperview];
    AddstoresBackview=nil;
    addstoresView=nil;
    fieldslbl=nil,defaluttaxLbl=nil,subtotallbl=nil,currencylbl=nil;
    dataField=nil;
    DefaulttaxBtn=nil,subtotalBtn=nil,currencyBtn=nil,savestoreDataBtn=nil,resetStoreDatabtn=nil;
    storename=nil,storeid=nil,email=nil,number=nil,street=nil,city=nil,postalcode=nil,country=nil,state=nil,subtotalStr=nil;
    taxesTable=nil,currencytable=nil;
    taxesArray=nil,currencyArray=nil;
    citytextField=nil,stateTextField=nil,CountrytextField=nil,postalTextField=nil;
    
    //edit stores view
    NSArray *EditsoreViewArray = EditsoreView.subviews;
    for (int i = 0; i<[EditsoreViewArray count]; i++) {
        UIView *vi =[EditsoreViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    NSArray *EditStoredataBackViewArray = EditStoredataBackView.subviews;
    for (int i = 0; i<[EditStoredataBackViewArray count]; i++) {
        UIView *vi =[EditStoredataBackViewArray objectAtIndex:i];
        [vi removeFromSuperview];
        vi = nil;
    }
    [editStoresView removeFromSuperview],[EditStoredataBackView removeFromSuperview];
    editStoresView=nil;
    editstoresTable=nil;
    [storenamesArray removeAllObjects], [storecitysArray removeAllObjects], [storeCountrysArray removeAllObjects], [storeStatesArray removeAllObjects],[storeIDSArray removeAllObjects];
    storenamesArray=nil,storecitysArray=nil,storeCountrysArray=nil,storeStatesArray=nil,storestateStr=nil,storeIDSArray=nil;
    editBtn=nil,deleteBtn=nil,viewbtn=nil;
    deleteStoreAlert=nil;
    viewStoredataBackView=nil;
    ViewStoredataTable=nil;
   
    AllkeysArray=nil,AllvaluesArray=nil;
    EditStoredataBackView=nil;
    EditsoreView=nil;
    EditFieldLbl=nil,EditdefaluttaxLbl=nil,Editsubtotallbl=nil,Editcurrencylbl=nil;
    EditdataField=nil;
    EditDefaulttaxBtn=nil,EditsubtotalBtn=nil,EditcurrencyBtn=nil,EditsavestoreDataBtn=nil,EditresetStoreDatabtn=nil;
    edittaxesTable=nil,editcurrencytable=nil;
    EditSubtotalStr=nil;
    changeStorename=nil,Changestoreid=nil,changeEmail=nil,Changenumber=nil,changestreet=nil,changeCity=nil,changePostal=nil,changeCountrty=nil,Changestate=nil,Changetax=nil,ChangeDiscount=nil,Changecurrency=nil;
    
    statesTable=nil,countrysTable=nil,citysTable=nil;
    [pastStatesArray  removeAllObjects], [pastCitysArray  removeAllObjects],[pastCountrysArray  removeAllObjects],[statesArray  removeAllObjects],[countrysArray removeAllObjects],[citysArray removeAllObjects];
    pastStatesArray=nil,pastCitysArray=nil,pastCountrysArray=nil,statesArray=nil,countrysArray=nil,citysArray=nil;
    
    StoreConnection=nil;
    StoreResponseData=nil;
    
    sationLbl=nil,Timelbl=nil,EmpIdlbl=nil;
    logoBtn=nil;
    
      storesCell=nil;
      viewStoresCell=nil;
    [editStoresView removeFromSuperview];
    [self.view removeFromSuperview];
    self.view=nil;
    
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{
    if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight||toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
        isLandScope=YES;
        
    }else
    {
        isLandScope=NO;
    }
   [self updateUI];
}



- (NSUInteger)supportedInterfaceOrientations // iOS 6 autorotation fix
{
    return UIInterfaceOrientationMaskAll;
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    NSArray *viewS = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[viewS objectAtIndex:1] animated:YES];
    [self releaseViews];
    // Dispose of any resources that can be recreated.
}

@end
